package com.andy.utils.excel.beesxicircle0613;

import com.alibaba.excel.EasyExcel;
import com.andy.utils.excel.beesxicircle0613.temp.BeesIsalesPocStatusCodeEnum;
import com.andy.utils.common.IMathUtils;

import java.util.List;

public class ExcelUtilService {

    public static void main(String[] args) {
        ExcelUtilService excelUtilService = new ExcelUtilService();
        //读取excel
        List<DemoModel> demoModels = excelUtilService.readExcel();

        //opt!!!
        excelUtilService.optDemoModel(demoModels);

        //写excel
        excelUtilService.writeExcel(demoModels);

    }

    /**
     * 处理excel业务逻辑
     * @param demoModelList
     */
    private void optDemoModel(List<DemoModel> demoModelList){
        for(DemoModel demoModel:demoModelList){
            Integer beesCode = IMathUtils.toInteger(demoModel.getStatus());
            Integer channelCheckStatus = IMathUtils.toInteger(demoModel.getChannelChangeStatus());
            Integer confirmStatus = IMathUtils.toInteger(demoModel.getConfirmStatus());
            Integer iSalesCode = BeesIsalesPocStatusCodeEnum.getISalesCode(beesCode, channelCheckStatus, confirmStatus);
            demoModel.setIsalesStatus(String.valueOf(iSalesCode));
        }
    }

    private static final String fileName = "C:\\Users\\ThinkPad\\Documents\\Work Files\\脚本修复文件\\bees x icircle isales状态修复\\testPoc.xlsx";
    private static final String fileNameOutput = "C:\\Users\\ThinkPad\\Documents\\Work Files\\脚本修复文件\\bees x icircle isales状态修复\\testPocOutput.xlsx";

    /**
     * 读excel
     * @return
     */
    public List<DemoModel> readExcel(){
        DemoListener demoListener = new DemoListener();
        // 这里默认读取第一个sheet
        EasyExcel.read(fileName, DemoModel.class, demoListener).sheet().doRead();

        return demoListener.list;
    }

    /**
     * 写excel
     * @return
     */
    public void writeExcel(List<DemoModel> demoModelList){
        EasyExcel.write(fileNameOutput, DemoModel.class).sheet("输出")
                .doWrite(demoModelList);
    }

}
